<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/6 0006
 * Time: 20:41
 */
class number implements Iterator
{
    private $start, $end;
    private $cur;


    public function __construct($start, $end)
    {
        $this->start = $start;
        $this->end = $end;
    }

    public function current()  //当前的的位置通常是储存的对象本身
    {
//        echo 3;
        // TODO: Implement current() method.
        return pow($this->cur, 2);
    }

    public function key()
    {
//        echo 4;
        // TODO: Implement key() method.
        return $this->cur;
    }

    public function next()
    {
//        echo 5;
        // TODO: Implement next() method.
        $this->cur++;
    }

    public function valid()
    {
//        echo 2;
        // TODO: Implement valid() method.
//        echo $this->cur."\n";
//        echo $this->end."\n";
        return $this->cur <= $this->end;
    }

    public function rewind()
    {
//        echo 1;
        // TODO: Implement rewind() method.
        $this->cur = $this->start;
    }

}

$obj = new number(3, 7);

foreach ($obj as $index => $item) {
    echo 'index =' . $index . 'val=' . $item . "\r\n";
}
//class myClass
//{
//    public $name = 'yfl';
//    public $sex  = '15';
//}
//$obj = new myClass();
//foreach ($obj as $index => $item) {
//       echo $obj[$index];
//}